//用promise封装
function fetch(options) {
    return new Promise(function (resolve, reject) {
        wx.request({
            url: options.url,
            data: options.data || {},
            header: options.header || {},
            method: options.method || 'GET',
            dataType: options.dataType || 'json',
            responseType: options.responseType || 'text',
            success: function (res) {
                // console.log(res)
                //回调函数
                // cb(res)
                if (res.statusCode == 200) {
                    resolve(res)
                }
            },
            fail: function (res) {
                reject(res)
                wx.showToast({
                    title: res || '网络请求错误',
                    duration: 3000,
                    mask: true
                })
            },
            complete: function (res) {},
        })
    })
}

//导出
module.exports = {
    fetchTime: fetch
}